<!DOCTYPE html>
<html>
<head>
    <title>机构管理</title>
    <script type="text/javascript">
        function popAddOrModify(id, level) {
            var parentOrgId = "";
            var orgLevel = "";
            if (parentOrgId != undefined && level != undefined) {
                parentOrgId = id;
                orgLevel = level;
            } else {
                parentOrgId = "JKTX";
                orgLevel = 1;
            }
            $.post("${absoluteContextPath}/system/organization/goAdd", {
                'parentOrgId': parentOrgId,
                orgLevel: orgLevel
            }, function (data) {
                var data = JSON.parse(data);
                if (data.returnCode == 1) {
                    $("#fromContent").html(data.content.data);
                } else {
                    $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                }
            });
        }

        function popEditOrModify(id) {
            var data = {};
            var url = '${absoluteContextPath}/system/organization/goEdit';
            if (id != undefined) {
                data.id = id;
            }
            $.ajax({
                url: url,
                type: 'post',
                data: data,
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        $("#fromContent").html(data.content.data);
                    } else {
                        $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                    }
                }
            });
        }

        function deleteOrg(id, orgId) {
            $.confirm({
                confirm: function () {
                    $("#confirmModal").modal("hide");
                    $.post("${absoluteContextPath}/system/organization/delete", {
                        'id': id,
                        'orgId': orgId
                    }, function (data) {
                        data = JSON.parse(data);
                        if (data.returnCode == 1) {
                            $.showMessage({parentId: "showMessage", message: "机构数据删除成功！", type: "success"});
                            refreshTable();

                        } else {
                            $.showMessage({parentId: "showMessage", message: "数据存在子项，请先删除子项！", type: "error"});
                        }
                    });
                }
            });
        }

        function refreshTable() {
            $.post("${absoluteContextPath}/system/organization/ajaxList", {
            }, function (data) {
                var data = JSON.parse(data);
                if (data.returnCode == 1) {
                    $("#tableContent").html(data.content.data);
                } else {
                    $.showMessage({parentId: "showMessage", message: "表格数据加载异常！", type: "success"});
                }
            });
        }

        function save() {
            $("#" + "organizationForm").ajaxSubmit({
                success: function (data) {
                    data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        $("#fromContent").html(data.content.data);
                        $.showMessage({parentId: "errorMessage", message: "机构信息保存成功！", type: "success"});
                        refreshTable();
                    } else {
                        $.showMessage({parentId: "errorMessage", message: "<strong>错误信息</strong>：机构" + data.returnMsg, type: "error"});
                    }
                }
            });
        }
    </script>
</head>
<body>

<div class="breadcrumbs">
    <ol class="breadcrumb">
        <li><a href="${absoluteContextPath}/home"><i class="fa fa-home"></i>首页</a></li>
        <li><a href="#">系统管理</a></li>
        <li class="active">机构管理</li>
    </ol>
</div>

<div class="main">
    <!-- row -->
    <div class="row">
        <div class="col-md-4">
            <section class="tile">
                <div id="showMessage"><#include "../../message.ftl" /></div>
                <div class="tile-body nopadding">
                    <div class="table-responsive" id="tableContent">
                    <#include "table.ftl"/>
                    </div>
                </div>
            </section>
        </div>
        <div class="col-md-8">
            <section class="tile">

                <div class="tile-body nopadding">
                    <div class="table-responsive" id="fromContent">

                    <#include "form.ftl"/>
                    </div>
                </div>
            </section>
        </div>
    </div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    </div>
</div>
</body>
</html>
